limsEquipScrap.detailPage = {
    getBtnToolbar: function (id, step) {
        var _this = this
        var buttons = [{
            type: 'button',
            text: 'GIKAM.BUTTON.BACK',
            icon: 'back',
            onClick: function () {
                workspace.window.goBack()
            }
        },]
        if (step) {
            if (step === 'edit') {
                buttons.push({
                    type: 'button',
                    text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                    icon: 'submit', color: 'success',
                    onClick: function () {
                        _this.submitSingle(id)
                    }
                })
            } else if (step === 'audit') {
                buttons.push({
                    type: 'button',
                    text: 'GIKAM.WORKFLOW.BUTTON.PASS',
                    icon: 'pass',
                    onClick: function () {
                        _this.passSingle(id)
                    }
                }, {
                    type: 'button',
                    text: 'GIKAM.WORKFLOW.BUTTON.REJECT',
                    icon: 'reject',
                    onClick: function () {
                        _this.rejectSingle(id)
                    }
                })
            } else {

            }
        }
        return {
            type: 'btnToolbar',
            items: buttons
        }
    },

    submitSingle: function (id) {
        var _this = this
        Gikam.create('workflow').submit({
            data: [{id: id}],
            pageObject: limsEquipScrap,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            workspace.window.goBack()
        })
    },

    passSingle: function (id) {
        var _this = this
        Gikam.create('workflow').pass({
            data: [{id: id}],
            pageObject: limsEquipScrap,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            workspace.window.goBack()
        })
    },

    rejectSingle: function (id) {
        var _this = this
        Gikam.create('workflow').reject({
            data: [{id: id}],
            pageObject: limsEquipScrap,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function () {
            workspace.window.goBack()
        })
    },

    getBaseInfoTab: function (id) {
        var _this = this
        return {
            type: 'tab',
            panels: [{
                title: 'GIKAM.FILE.ATTACHMENT',
                items: [{
                    type: 'uploader',
                    id: 'lims-equip-scrap-uploader',
                    dbTable: 'T_LIMS_EQUIP_SCRAP',
                    readonly: !_this.param.step || _this.param.step !== 'edit',
                    bizId: id,
                }]
            }, {
                title: 'T_CORE_FILE.OPERATE.OPERATION.RECORD',
                items: [{
                    type: 'grid',
                    id: 'lims-equip-scrap-operation-record',
                    columns: limsEquipScrap.getFlowListColumns(),
                    url: IFM_CONTEXT + '/secure/core/module/sys/bpmn-comments/queries?table=T_LIMS_EQUIP_SCRAP&id=' + id
                }]
            }]
        }
    },

    createPage: function () {
        let _this = this
        Gikam.create('layout', {
            center: {
                items: [this.getBtnToolbar(_this.param.id, _this.param.step), this.getBaseInfoTab(_this.param.id)]
            },
            renderTo: workspace.window.$dom
        })
        return this
    },

    init: function (param) {
        this.param = param
        this.createPage()
    }
}
